package com.nlx.notes.module.controller.user;

import com.nlx.notes.module.bean.dto.login.UserLoginDTO;
import com.nlx.notes.module.bean.dto.user.UserInfoUpdateDTO;
import com.nlx.notes.module.bean.vo.user.UserBaseInfoVO;
import com.nlx.notes.module.core.util.JSONUtils;
import com.nlx.notes.module.service.user.UserViewService;
import com.nlx.notes.support.context.UserHolder;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
@RequestMapping("/user")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class UserInfoController {

    final UserViewService userViewService;

    @PostMapping(value = "/v1/bind-phone")
    public Boolean bindPhone(@RequestBody UserLoginDTO userLoginDTO){
        log.info("获取当前用户的基本信息 -> {}", UserHolder.getUserContext().getUserPhone());
        return userViewService.bindPhone(UserHolder.getUserContext().getId(),userLoginDTO);
    }

    @PostMapping(value = "/v1/update-user-info")
    public Boolean updateUserInfo(@RequestBody UserInfoUpdateDTO userInfoUpdateDTO){
        log.info("修改用户的个人信息，用户：{}，入参：{}",UserHolder.getUserContext().getId(), JSONUtils.toString(userInfoUpdateDTO));
        return userViewService.updateUserInfo(userInfoUpdateDTO,UserHolder.getUserContext().getId());
    }

}
